home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
FromTheMag
/
JW FLV MEDIA PLAYER 4.2
/
mediaplayer.exe
/
player.swf
/
scripts
/
com
/
jeroenwijering
/
player
/
View.as
< prev
Wrap
Text File
|
2008-11-04
|
11KB
|
357 lines
package com.jeroenwijering.player
{
import com.carlcalderon.arthropod.Debug;
import com.jeroenwijering.events.AbstractView;
import com.jeroenwijering.events.ControllerEvent;
import com.jeroenwijering.events.ModelEvent;
import com.jeroenwijering.events.ViewEvent;
import com.jeroenwijering.utils.Strings;
import flash.display.MovieClip;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.system.Capabilities;
import flash.system.Security;
import flash.ui.ContextMenu;
import flash.utils.setTimeout;
public class View extends AbstractView
{
private var listeners:Array;
private var loader:SPLoader;
private var _skin:MovieClip;
private var _config:Object;
private var model:Model;
private var controller:Controller;
private var context:ContextMenu;
public function View(param1:Object, param2:MovieClip, param3:Controller, param4:Model, param5:SPLoader)
{
super();
Security.allowDomain("*");
_config = param1;
_config["client"] = "FLASH " + Capabilities.version;
_skin = param2;
if(_config["resizing"])
{
_skin.stage.scaleMode = "noScale";
_skin.stage.align = "TL";
_skin.stage.addEventListener(Event.RESIZE,resizeHandler);
}
loader = param5;
controller = param3;
model = param4;
setListening();
if(ExternalInterface.available && _skin.loaderInfo.url.indexOf("http") == 0)
{
listeners = new Array();
setJavascript();
setTimeout(playerReady,50);
}
if(config["file"])
{
setTimeout(sendEvent,200,ViewEvent.LOAD,config);
}
}
override public function get config() : Object
{
return _config;
}
private function addJSViewListener(param1:String, param2:String) : Boolean
{
listeners.push({
"target":"VIEW",
"type":param1.toUpperCase(),
"callee":param2
});
return true;
}
private function forward(param1:String, param2:String, param3:Object) : void
{
var _loc4_:* = null;
var _loc5_:* = null;
var _loc6_:* = null;
var _loc7_:Object = null;
_loc4_ = "";
for(_loc5_ in param3)
{
_loc4_ += _loc5_ + ":" + param3[_loc5_] + ",";
}
if(_loc4_.length > 0)
{
_loc4_ = "(" + _loc4_.substr(0,_loc4_.length - 1) + ")";
}
if(config["tracecall"] == "arthropod")
{
_loc7_ = {
"CONTROLLER":"0xFF6666",
"VIEW":"0x66FF66",
"MODEL":"0x6666FF"
};
Debug.log(param2 + " " + _loc4_,_loc7_[param1]);
}
else if(config["tracecall"])
{
ExternalInterface.call(config["tracecall"],param1 + ": " + param2 + " " + _loc4_);
}
else
{
trace(param1 + ": " + param2 + " " + _loc4_);
}
if(!param3)
{
param3 = new Object();
}
param3.id = ExternalInterface.objectID;
param3.client = config["client"];
param3.version = config["version"];
for(_loc6_ in listeners)
{
if(listeners[_loc6_]["target"] == param1 && listeners[_loc6_]["type"] == param2)
{
ExternalInterface.call(listeners[_loc6_]["callee"],param3);
}
}
}
private function getPlaylist() : Array
{
return controller.playlist;
}
private function addJSModelListener(param1:String, param2:String) : Boolean
{
listeners.push({
"target":"MODEL",
"type":param1.toUpperCase(),
"callee":param2
});
return true;
}
private function getConfig() : Object
{
var _loc1_:Object = null;
var _loc2_:* = null;
_loc1_ = new Object();
for(_loc2_ in _config)
{
if(_loc2_.indexOf(".") == -1)
{
_loc1_[_loc2_] = _config[_loc2_];
}
}
return _loc1_;
}
override public function get playlist() : Array
{
return controller.playlist;
}
private function playerReady() : void
{
var dat:Object = null;
if(ExternalInterface.available)
{
dat = {
"id":config["id"],
"client":config["client"],
"version":config["version"]
};
try
{
ExternalInterface.call("playerReady",dat);
}
catch(err:Error)
{
}
}
}
private function setListening() : void
{
if(config["tracecall"] == "arthropod")
{
Debug.clear();
}
addControllerListener(ControllerEvent.ERROR,setController);
addControllerListener(ControllerEvent.ITEM,setController);
addControllerListener(ControllerEvent.MUTE,setController);
addControllerListener(ControllerEvent.PLAY,setController);
addControllerListener(ControllerEvent.PLAYLIST,setController);
addControllerListener(ControllerEvent.QUALITY,setController);
addControllerListener(ControllerEvent.RESIZE,setController);
addControllerListener(ControllerEvent.SEEK,setController);
addControllerListener(ControllerEvent.STOP,setController);
addControllerListener(ControllerEvent.VOLUME,setController);
addModelListener(ModelEvent.BUFFER,setModel);
addModelListener(ModelEvent.ERROR,setModel);
addModelListener(ModelEvent.LOADED,setModel);
addModelListener(ModelEvent.META,setModel);
addModelListener(ModelEvent.STATE,setModel);
addModelListener(ModelEvent.TIME,setModel);
addViewListener(ViewEvent.FULLSCREEN,setView);
addViewListener(ViewEvent.ITEM,setView);
addViewListener(ViewEvent.LINK,setView);
addViewListener(ViewEvent.LOAD,setView);
addViewListener(ViewEvent.MUTE,setView);
addViewListener(ViewEvent.NEXT,setView);
addViewListener(ViewEvent.PLAY,setView);
addViewListener(ViewEvent.PREV,setView);
addViewListener(ViewEvent.QUALITY,setView);
addViewListener(ViewEvent.REDRAW,setView);
addViewListener(ViewEvent.SEEK,setView);
addViewListener(ViewEvent.STOP,setView);
addViewListener(ViewEvent.TRACE,setView);
addViewListener(ViewEvent.VOLUME,setView);
}
private function setView(param1:ViewEvent) : void
{
forward("VIEW",param1.type,param1.data);
}
override public function addModelListener(param1:String, param2:Function) : void
{
model.addEventListener(param1.toUpperCase(),param2);
}
private function setController(param1:ControllerEvent) : void
{
forward("CONTROLLER",param1.type,param1.data);
}
private function addJSControllerListener(param1:String, param2:String) : Boolean
{
listeners.push({
"target":"CONTROLLER",
"type":param1.toUpperCase(),
"callee":param2
});
return true;
}
private function setJavascript() : *
{
try
{
if(ExternalInterface.objectID)
{
_config["id"] = ExternalInterface.objectID;
}
ExternalInterface.addCallback("getConfig",getConfig);
ExternalInterface.addCallback("getPlaylist",getPlaylist);
ExternalInterface.addCallback("addControllerListener",addJSControllerListener);
ExternalInterface.addCallback("addModelListener",addJSModelListener);
ExternalInterface.addCallback("addViewListener",addJSViewListener);
ExternalInterface.addCallback("sendEvent",sendEvent);
ExternalInterface.addCallback("loadPlugin",loadPlugin);
}
catch(err:Error)
{
}
}
private function setModel(param1:ModelEvent) : void
{
forward("MODEL",param1.type,param1.data);
}
override public function addControllerListener(param1:String, param2:Function) : void
{
controller.addEventListener(param1.toUpperCase(),param2);
}
override public function sendEvent(param1:String, param2:Object = undefined) : void
{
var _loc3_:Object = null;
param1 = param1.toUpperCase();
_loc3_ = new Object();
switch(param1)
{
case "TRACE":
_loc3_["message"] = param2;
break;
case "LINK":
if(param2 != null)
{
_loc3_["index"] = param2;
}
break;
case "LOAD":
_loc3_["object"] = param2;
break;
case "ITEM":
if(param2 > -1)
{
_loc3_["index"] = param2;
}
break;
case "SEEK":
_loc3_["position"] = param2;
break;
case "VOLUME":
_loc3_["percentage"] = param2;
break;
default:
if(param2 != null && param2 != "")
{
if(param2 == true || param2 == "true")
{
_loc3_["state"] = true;
}
else if(param2 == false || param2 == "false")
{
_loc3_["state"] = false;
}
}
}
dispatchEvent(new ViewEvent(param1,_loc3_));
}
private function resizeHandler(param1:Event = undefined) : void
{
dispatchEvent(new ViewEvent(ViewEvent.REDRAW));
}
public function loadPlugin(param1:String, param2:String = null) : Boolean
{
var _loc3_:Array = null;
var _loc4_:* = null;
var _loc5_:Array = null;
if(param2 != null && param2 != "")
{
_loc3_ = param2.split("&");
for(_loc4_ in _loc3_)
{
_loc5_ = _loc3_[_loc4_].split("=");
_config[_loc5_[0]] = Strings.serialize(_loc5_[1]);
}
}
loader.loadPlugins(param1);
return true;
}
override public function addViewListener(param1:String, param2:Function) : void
{
this.addEventListener(param1.toUpperCase(),param2);
}
override public function get skin() : MovieClip
{
return _skin;
}
}
}